<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('修改周报')" />
    <th:block th:include="include :: datetimepicker-css" />
    <th:block th:include="include :: jasny-bootstrap-css" />
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-weekly-edit" th:object="${adminWeekly}">
            <div class="form-group">
                <label class="col-sm-3 control-label">周报起始日期：</label>
                <div class="col-sm-8">
                    <div class="input-group date">
                        <input name="weeklyDateStart"  th:value="${#dates.format(adminWeekly.weeklyDateStart, 'yyyy-MM-dd')}" class="form-control" placeholder="yyyy-MM-dd" type="text">
                        <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
                    </div>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">周报截止日期：</label>
                <div class="col-sm-8">
                    <div class="input-group date">
                        <input name="weeklyDateEnd" th:value="${#dates.format(adminWeekly.weeklyDateEnd, 'yyyy-MM-dd')}" class="form-control" placeholder="yyyy-MM-dd" type="text">
                        <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
                    </div>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">附件：</label>
                <div class="col-sm-8">
                    <div class="fileinput fileinput-exists" data-provides="fileinput">
                        <span class="btn btn-white btn-file"><span class="fileinput-new">选择文件</span><span class="fileinput-exists">更改</span><input type="file" name="attachmentFile"></span>
                        <span class="fileinput-filename"><a th:href="*{attachmentPath}">[[${adminWeekly.attachmentName}]]</a></span>
                        <a href="#" class="close fileinput-exists" data-dismiss="fileinput" style="float: none">&times;</a>
                    </div>
                </div>
            </div>
            <input name="weeklyId" th:field="*{weeklyId}" type="hidden">
            <input name="userId" th:field="*{userId}" type="hidden">
            <div id="taskContent">
                    <span style="float:right;position:relative; width:80px;height:20px;" class="bs-glyphicons glyphicon glyphicon-plus" id="addTask">
                        <span onclick="addTask()"><a>添加任务</a></span>
                    </span>
                <div id="adminTask" th:each="t, stat:${adminWeekly.weeklyJobs}">
                    <div class="ibox float-e-margins" >
                        <div class="ibox-title">
                            <h5>工作任务</h5><input th:name="'weeklyJobs['+${stat.index}+'].jobId'" class="form-control" type="hidden" th:value="${t.jobId}">
                        </div>
                        <div class="ibox-content">
                            <div class="form-group">
                                <label class="col-sm-3 control-label">产品/项目：</label>
                                <div class="col-sm-8">
                                    <select th:name="'weeklyJobs['+${stat.index}+'].productType'" onChange="selectProduct(this)" class="form-control">
                                        <option value="">请选择</option>
                                        <option value="0" th:selected="${t.productType==0}">产品</option>
                                        <option value="1" th:selected="${t.productType==1}">项目</option>
                                    </select>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-3 control-label">产品/项目名称：</label>
                                <div class="col-sm-8">
                                    <select th:name="'weeklyJobs['+${stat.index}+'].productId'" class="form-control">
                                        <option value="">请选择产品/项目</option>
                                    </select>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-3 control-label">需求来源：</label>
                                <div class="col-sm-8">
                                    <select th:name="'weeklyJobs['+${stat.index}+'].projectId'" class="form-control " th:with="project=${@sysProjectService.selectSysProjectList(null)}">
                                        <option value="0">本部</option>
                                        <option th:each="p : ${project}" th:text="${p.projectName}" th:value="${p.projectId}" th:selected="${t.projectId==p.projectId}"></option>
                                    </select>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-3 control-label">本周进度是否延期：</label>
                                <div class="col-sm-8">
                                    <div class="radio check-box">
                                        <label>
                                            <block th:if="${t.isDelay} eq 0" >
                                                <input type="radio"  value="0" checked th:name="'weeklyJobs['+${stat.index}+'].isDelay'"> <i></i> 正常
                                            </block>
                                            <block th:unless="${t.isDelay} eq 0" >
                                                <input type="radio"  value="0" th:name="'weeklyJobs['+${stat.index}+'].isDelay'"> <i></i> 正常
                                            </block>
                                        </label>
                                    </div>
                                    <div class="radio check-box">
                                        <label>
                                            <block th:if="${t.isDelay} eq 1" >
                                                <input type="radio"  value="1" checked th:name="'weeklyJobs['+${stat.index}+'].isDelay'"> <i></i> 延期
                                            </block>
                                            <block th:unless="${t.isDelay} eq 1" >
                                                <input type="radio"  value="1" th:name="'weeklyJobs['+${stat.index}+'].isDelay'"> <i></i> 延期
                                            </block>

                                        </label>
                                    </div>
                                </div>
                            </div>
                            <div class="form-group" shiro:hasRole="groupLeader">
                                <label class="col-sm-3 control-label"><span style="color: red">*</span>项目进度(%)：</label>
                                <div class="col-sm-8">
                                    <input th:name="'weeklyJobs['+${stat.index}+'].progress'" class="form-control" type="text" th:value="${t.progress}" digits="true" required>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-3 control-label">本周工作内容：</label>
                                <div class="col-sm-8">
                                    <textarea th:name="'weeklyJobs['+${stat.index}+'].jobContent'" class="form-control" required>[[${t.jobContent}]]</textarea>
                                </div>
                            </div>
                            <div class="form-group" shiro:hasRole="groupLeader">
                                <label class="col-sm-3 control-label">下周工作计划：</label>
                                <div class="col-sm-8">
                                    <textarea th:name="'weeklyJobs['+${stat.index}+'].jobPlan'" class="form-control" required>[[${t.jobPlan}]]</textarea>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-3 control-label">计划完成需求数量：</label>
                                <div class="col-sm-8">
                                    <input th:name="'weeklyJobs['+${stat.index}+'].planDemandAmount'" class="form-control" type="text" th:value="${t.planDemandAmount}" digits="true">
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-3 control-label">实际完成需求数量：</label>
                                <div class="col-sm-8">
                                    <input th:name="'weeklyJobs['+${stat.index}+'].actualDemandAmount'" class="form-control" type="text" th:value="${t.actualDemandAmount}" digits="true">
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-3 control-label">计划完成任务数量：</label>
                                <div class="col-sm-8">
                                    <input th:name="'weeklyJobs['+${stat.index}+'].planTaskAmount'" class="form-control" type="text" th:value="${t.planTaskAmount}" digits="true">
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-3 control-label">实际完成任务数量：</label>
                                <div class="col-sm-8">
                                    <input th:name="'weeklyJobs['+${stat.index}+'].actualTaskAmount'" class="form-control" type="text" th:value="${t.actualTaskAmount}" digits="true">
                                </div>
                            </div>

                            <div class="form-group" shiro:hasRole="developer">
                                <label class="col-sm-3 control-label">产品转测数量：</label>
                                <div class="col-sm-8">
                                    <input th:name="'weeklyJobs['+${stat.index}+'].toTestAmount'" class="form-control" type="text" th:value="${t.toTestAmount}" digits="true">
                                </div>
                            </div>
                            <div class="form-group" shiro:hasRole="developer">
                                <label class="col-sm-3 control-label">新增缺陷数量：</label>
                                <div class="col-sm-8">
                                    <input th:name="'weeklyJobs['+${stat.index}+'].newBugAmount'" class="form-control" type="text" th:value="${t.newBugAmount}" digits="true">
                                </div>
                            </div>
                            <div class="form-group" shiro:hasRole="developer">
                                <label class="col-sm-3 control-label">修复缺陷数量：</label>
                                <div class="col-sm-8">
                                    <input th:name="'weeklyJobs['+${stat.index}+'].fixBugAmount'" class="form-control" type="text" th:value="${t.fixBugAmount}" digits="true">
                                </div>
                            </div>
                            <div class="form-group" shiro:hasRole="productManager">
                                <label class="col-sm-3 control-label">产品体验数量：</label>
                                <div class="col-sm-8">
                                    <input th:name="'weeklyJobs['+${stat.index}+'].productExperienceAmount'" class="form-control" type="text" th:value="${t.productExperienceAmount}" digits="true">
                                </div>
                            </div>
                            <div class="form-group" shiro:hasRole="productManager">
                                <label class="col-sm-3 control-label">产品体验通过数量：</label>
                                <div class="col-sm-8">
                                    <input th:name="'weeklyJobs['+${stat.index}+'].productExperiencePassAmount'" class="form-control" type="text" th:value="${t.productExperiencePassAmount}" digits="true">
                                </div>
                            </div>
                            <div class="form-group" shiro:hasRole="productManager">
                                <label class="col-sm-3 control-label">产品设计评审会议数量：</label>
                                <div class="col-sm-8">
                                    <input th:name="'weeklyJobs['+${stat.index}+'].designReviewAmount'" class="form-control" type="text" th:value="${t.designReviewAmount}" digits="true">
                                </div>
                            </div>
                            <div class="form-group" shiro:hasRole="productManager">
                                <label class="col-sm-3 control-label">产品设计评审会议通过数量：</label>
                                <div class="col-sm-8">
                                    <input th:name="'weeklyJobs['+${stat.index}+'].designReviewPassAmount'" class="form-control" type="text" th:value="${t.designReviewPassAmount}" digits="true">
                                </div>
                            </div>
                            <div class="form-group" shiro:hasRole="tester">
                                <label class="col-sm-3 control-label">发现缺陷数量：</label>
                                <div class="col-sm-8">
                                    <input th:name="'weeklyJobs['+${stat.index}+'].detectBugAmount'" class="form-control" type="text" th:value="${t.detectBugAmount}" digits="true">
                                </div>
                            </div>
                            <div class="form-group" shiro:hasRole="tester">
                                <label class="col-sm-3 control-label">关闭缺陷数量：</label>
                                <div class="col-sm-8">
                                    <input th:name="'weeklyJobs['+${stat.index}+'].closeBugAmount'" class="form-control" type="text" th:value="${t.closeBugAmount}" digits="true">
                                </div>
                            </div>
                            <div class="form-group" shiro:hasRole="operationEngineer">
                                <label class="col-sm-3 control-label">配置项目产品数量：</label>
                                <div class="col-sm-8">
                                    <input th:name="'weeklyJobs['+${stat.index}+'].deployProductAmount'" class="form-control" type="text" th:value="${t.deployProductAmount}" digits="true">
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-3 control-label">文档贡献数量：</label>
                                <div class="col-sm-8">
                                    <input th:name="'weeklyJobs['+${stat.index}+'].documentAmount'" class="form-control" type="text" th:value="${t.documentAmount}" digits="true">
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-3 control-label">培训数量：</label>
                                <div class="col-sm-8">
                                    <input th:name="'weeklyJobs['+${stat.index}+'].trainingAmount'" class="form-control" type="text" th:value="${t.trainingAmount}" digits="true">
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-3 control-label">备注：</label>
                                <div class="col-sm-8">
                                    <textarea th:name="'weeklyJobs['+${stat.index}+'].remark'" class="form-control">[[${t.remark}]]</textarea>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>

        </form>
    </div>
    <th:block th:include="include :: footer" />
    <th:block th:include="include :: datetimepicker-js" />
    <th:block th:include="include :: jasny-bootstrap-js" />
    <script th:inline="javascript">
        var num=0
        function selectProduct(sel){
            var str = sel.name;
            let index = str.indexOf(".")
            str =str .substring(0,index);
            str += ".productId";
            var url;
            var productType= sel.value;
            url = "/system/product/"+ productType;
            if ("" === productType) {
                $("select[name='"+str+"']").empty();
                $("select[name='"+str+"']").append
                ('<option value="">请选择产品/项目</option>');
                $("select[name='"+str+"']").selectpicker('refresh');
                $("select[name='"+str+"']").selectpicker('render');
                return;
            }
            $.ajax({
                cache: true,
                type: "GET",
                url: url,
                async: false,
                success: function(result) {
                    data = result.data
                    if (result.code == web_status.SUCCESS) {
                        $("select[name='"+str+"']").empty();
                        for(var i in data){
                            // json = eval("("+data[i]+")");
                            var productId = data[i].productId;
                            var productName =data[i].productName;
                            $("select[name='"+str+"']").append
                            ('<option value="'+productId+'">'+productName+'</option>');
                        };
                        $("select[name='"+str+"']").selectpicker('refresh');
                        $("select[name='"+str+"']").selectpicker('render');
                    } else {
                        $.modal.alertError(result.msg);
                    }
                }
            });
        };
        var prefix = ctx + "system/weekly";
        function addTask() {
            var url;
            url = prefix + "/addTask/"+num;
            $.ajax({
                cache: true,
                type: "GET",
                url: url,
                async: false,
                success: function(result) {
                    $("#addTask").after(result);
                    num++;
                }
            });
        };
        $("#form-weekly-edit").validate({
            focusCleanup: true
        });

        function submitHandler() {
            if ($.validate.form()) {
                $.operate.saveSync(prefix + "/edit", new FormData(document.getElementById('form-weekly-edit')));
            }
        }

        $("input[name='weeklyDate']").datetimepicker({
            format: "yyyy-mm-dd",
            minView: "month",
            autoclose: true
        });

        $("input[name='modifyTime']").datetimepicker({
            format: "yyyy-mm-dd",
            minView: "month",
            autoclose: true
        });
        function selectProductType(values, index){
            var productType = values.productType;
            var str = 'weeklyJobs['+index+'].productId';
            var url = "/system/product/"+ productType;
            $.ajax({
                cache: true,
                type: "GET",
                url: url,
                async: false,
                success: function(result) {
                    data = result.data
                    if (result.code == web_status.SUCCESS) {
                        $("select[name='"+str+"']").empty();
                        for(var i in data){
                            var productId = data[i].productId;
                            var productName =data[i].productName;
                            var flg = values.productId==productId;
                            if (flg) {
                                $("select[name='"+str+"']").append
                                ('<option value="'+productId+'" selected="selected">'+productName+'</option>');
                            } else {
                                $("select[name='"+str+"']").append
                                ('<option value="'+productId+'" >'+productName+'</option>');
                            }

                        };
                        $("select[name='"+str+"']").selectpicker('refresh');
                        $("select[name='"+str+"']").selectpicker('render');
                    } else {
                        $.modal.alertError(result.msg);
                    }
                }
            });
        }
        function delTask(num) {
            var dev = "#div_" + num;
            alert(dev);
            $(dev).remove();
        };
        $(function() {
            $("input[name='weeklyDateStart']").datetimepicker({
                format: "yyyy-mm-dd",
                minView: "month",
                autoclose: true
            }).on('changeDate', function(event) {
                var value = $("input[name='weeklyDateStart']").val();
                if ('' == value) {
                    return;
                }
                url = prefix + "/friday/" + value;
                $.ajax({
                    cache: true,
                    type: "GET",
                    url: url,
                    async: false,
                    success: function(result) {
                        data = result.data
                        if (result.code == web_status.SUCCESS) {
                            $("input[name='weeklyDateEnd']").val(data);
                        } else {
                            $.modal.alertError(result.msg);
                        }
                    }
                });
            });
            $("input[name='weeklyDateEnd']").datetimepicker({
                format: "yyyy-mm-dd",
                minView: "month",
                autoclose: true
            });
            num = [[${adminWeekly.weeklyJobs.size()}]]+1;
            var jobs = [[${adminWeekly.weeklyJobs}]];
            jobs.forEach(selectProductType);
        });
    </script>
</body>
</html>